package com.moli.lumpSugar.user.controller;


import cn.hutool.core.collection.CollectionUtil;
import com.moli.lumpSugar.user.dao.UserRoleDao;
import com.moli.lumpSugar.user.domain.entity.UserRole;
import com.moli.lumpSugar.user.domain.enums.RoleEnum;
import com.moli.lumpSugar.user.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author zhangjt
 * @since 2024-10-27
 */
@RestController
@RequestMapping("/sapi/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;
    @Autowired
    private UserRoleDao userRoleDao;

    @GetMapping("/hasPower")
    public Boolean hasPower(Long uid,RoleEnum role){
        return roleService.hasPower(uid, role);
    }

    @GetMapping("/getUserRoles")
    public List<UserRole> getUserRoles(Long uid){
        List<UserRole> userRoles = userRoleDao.listByUid(uid);
        return CollectionUtil.isNotEmpty(userRoles) ? userRoles : new ArrayList<>();
    }

}

